import http from './http'
import server from 'config/server'

export default {
  /**
   * 获取设备信息
   * 获取单个设备详细信息。
   * @param  {productId}
   * @param  {deviceId}
   * @return {Promise}
    {
      "id":"设备ID",
      "mac":"MAC地址",
      "is_active":"是否激活",
      "active_date":"激活时间",
      "is_online":"是否在线",
      "last_login":"最近登录时间",
      "active_code":"激活码",
      "authorize_code":"认证码",
      "mcu_mod":"MCU型号",
      "mcu_version":"MCU版本号",
      "firmware_mod":"固件型号",
      "firmware_version":"固件版本号",
      "corp_id":"企业ID",
      "productId":"产品ID",
      "region_id":"所在区域ID"
    }
   */
  getInfo (productId, deviceId) {
    return http.get(
      `${server.host}/v2/product/${productId}/device/${deviceId}`
    )
  },

  /**
   * 查询设备列表
   * @param  {productId}
   * @param  {Object} params
      {
        "offset":"请求列表的偏移量",
        "limit":"请求数量",
        "filter":["字段A","字段B"],
        "query":
      {
        "filed1":{"$in":["字段值","字段值"]},
        "filed3":{"$lt":"字段值"}
      },
      "order":
      {
        "filed1":"desc",
        "filed2":"asc"
      }
    }
   * @return {Promise}
      {
        "count":"实际返回的条目数",
        "list":
        [
          {
            "id":"设备ID",
            "mac":"MAC地址",
            "is_active":"是否激活",
            "active_date":"激活时间",
            "is_online":"是否在线",
            "last_login":"最近登录时间",
            "active_code":"激活码",
            "authorize_code":"认证码",
            "mcu_mod":"MCU型号",
            "mcu_version":"MCU版本号",
            "firmware_mod":"固件型号",
            "firmware":"固件版本号",
            "productId":"产品ID",
            "region_id":"所在区域ID"
          }
        ]
      }
   */
  getList (productId, params) {
    return http.post(
      `${server.host}/v2/product/${productId}/devices`, params
    )
  },

  /**
   * 查询设备上下线记录
   * @param  {String} deviceId 设备 ID
   */
  getRecords (params) {
    return http.post(
      `${server.host}/v2/device_session_log`, params
    )
  },

  /**
   * 获取数据端点值
   * @param  {String} deviceId 设备 ID
   */
  getDatapointValues (deviceId) {
    return http.get(
      `${server.host}/v2/diagnosis/device/probe/${deviceId}`
    )
  }
}
